package org.tagging.utils;

import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.tagging.exception.LoginWrongPlaceException;
import org.tagging.exception.UsernameAlreadyExistException;
import org.tagging.model.TaggingUser;

public class Asserts {

    public static void userNotNull(TaggingUser user, String message) {
        if (user == null) {
            throw new UsernameNotFoundException(message);
        }
    }

    public static void userNull(TaggingUser u, String message) throws UsernameAlreadyExistException {
        if (u != null) {
            throw new UsernameAlreadyExistException(message);
        }
    }

    public static void isAdmin(Integer role, String message) throws LoginWrongPlaceException {
        if (!role.equals(RoleEnum.ADMIN.value())) {
            throw new LoginWrongPlaceException(message);
        }
    }

    public static void isUser(Integer role, String message) throws LoginWrongPlaceException {
        if (!role.equals(RoleEnum.USER.value())) {
            throw new LoginWrongPlaceException(message);
        }
    }
}
